<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title>消息日志表</title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/header.jsp" %>

				<script type="text/javascript">
					$(function () {
						$('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
						$('#endTime').datebox('setValue', getNowFormatDate());
						bindgrid();
					});
				</script>
				<script>
					function del(node) {
						$.ajax({
							type: "delete",
							url: 'sys/message/delete?msgId=msgId',
							//                dataType: "xml",				
							success: function (data) {
								$.messager.alert('消息', data);
								$('#add').window('close');
								bindgrid();
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								$.messager.alert('消息', errorThrown);
							}
						});
					}

					function save() {
						$('#fm').form('submit', {
							url: 'sys/message/save',
							iframe: false,
							onSubmit: function () {
								return $(this).form('validate');
							},
							success: function (result) {
								var result = eval('(' + result + ')');
								if (result.errorMsg) {
									$.messager.show({
										title: 'Error',
										msg: result.errorMsg
									});
								} else {
									$('#dlg').dialog('close'); // close the dialog
									$('#dg').datagrid('reload'); // reload the user data
								}
							}
						});
					}

					function editrow() {
						//编辑用户
						var row = $('#dg').datagrid('getSelected');
						if (row) {
							$('#add').window('open');
							$('#fm').form('load', row);

						} else {
							$.messager.alert('消息', '请选中一个用户');
						}
					}
				</script>
				<script>
					function selectList() {
						var startTime = $('#startTime').datebox('getValue')
						var endTime = $('#endTime').datebox('getValue')
						var dg = $('#dg');
						dg.datagrid('enableFilter');
						dg.datagrid('load', {
							startTime: startTime ? startTime : '',
							endTime: endTime ? endTime : ''
						});
					}
					function bindgrid() {
						var startTime = $('#startTime').datebox('getValue')
						var endTime = $('#endTime').datebox('getValue')
						$('#dg').datagrid({
							title: '消息列表',
							queryParams: {
								startTime: startTime,
								endTime: endTime
							},
							url: "sys/message/selectList",
							iconCls: 'icon-application',
							width: getWidth(0.98),
							height: 400,
							filterDelay: 0,
							nowrap: true,
							rownumbers: true,
							animate: false,
							collapsible: false,
							clientPaging: false,
							remoteFilter: true,
							singleSelect: true,
							pagination: true,
							remoteSort: true,
							columns: [[{
								field: 'msgId',
								title: '消息ID',
								sortable: true,
								hidden: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgContent',
								title: '消息内容',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgSendId',
								title: '发送人ID',
								sortable: true,
								hidden: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgSendName',
								title: '发送人姓名',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgSendTime',
								title: '发送时间',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgReceiveId',
								title: '接收人ID',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgReceiveName',
								title: '接收人姓名',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgReceiveTime',
								title: '接收时间',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'msgType',
								title: '消息类型',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'createTime',
								title: 'create_time',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'createName',
								title: 'create_name',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'createId',
								title: 'create_id',
								sortable: true,
								hidden: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'updateId',
								title: 'update_id',
								sortable: true,
								hidden: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'updateName',
								title: 'update_name',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'updateTime',
								title: 'update_time',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'delFlag',
								title: 'del_flag',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'status',
								title: 'status',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}, {
								field: 'remark',
								title: 'remark',
								sortable: true,
								formatter: function (val, rec) {
									return val ? unescape(val) : '';
								}
							}]],
							toolbar: [{
								text: '推送',
								iconCls: 'icon-add',
								handler: function () {
									let row = $('#dg').datagrid('getSelected');
									if (!row) {
										$.messager.alert('提示', '请选择一条数据');
										return
									} else {
										$.messager.confirm('提示', '确定要推送吗?',
											function (r) {
												if (r) {
													send(row);
												}
											});
									}
								}
							},],
							onLoadSuccess: function () {
							},
							onDblClickRow: function () {
								editrow();
							}
						});
						$('#dg').datagrid('enableFilter');
					}


					function send(row) {
						$.ajax({
							type: "post",
							url: 'sys/message/send?',
							//                dataType: "xml",	
							data: { id: row.msgId },
							success: function (data) {
								$.messager.alert('消息', data.msg);
								selectList();
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								$.messager.alert('消息', errorThrown);
							}
						});
					}
				</script>
				<style scoped="scoped">
					.textbox {
						height: 20px;
						margin: 0;
						padding: 0 2px;
						box-sizing: content-box;
					}

					/*.table tr {
        height: 15px;
    }*/
				</style>
				<div style="margin: 5px 0px">
					<%-- 搜索框 --%>
						<label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox" name="startTime"
							id="startTime"
							data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
							value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
							class="easyui-datebox" name="endTime" id="endTime"
							data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
							style="width: 150px" /> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
							class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="selectList()">查询</a>
				</div>
				<table id="dg"></table>


				<div id="add" class="easyui-window" closed="true" modal="true" title="用户信息"
					style="width: 500px; height: 450px; padding: 10px 20px">
					<form id="fm" class="ssec-form">
						<table class="table">
							<tr>
								<td>
									<div class="ssec-label">消息ID：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgId" name="msgId" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">消息内容：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgContent" name="msgContent" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">发送人ID：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgSendId" name="msgSendId" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">发送人姓名：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgSendName" name="msgSendName" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">发送时间：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgSendTime" name="msgSendTime" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">接收人ID：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgReceiveId" name="msgReceiveId" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">接收人姓名：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgReceiveName" name="msgReceiveName"
											class="easyui-validatebox textbox" data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">接收时间：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgReceiveTime" name="msgReceiveTime"
											class="easyui-validatebox textbox" data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">消息类型：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="msgType" name="msgType" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">create_time：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="createTime" name="createTime" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">create_name：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="createName" name="createName" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">create_id：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="createId" name="createId" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">update_id：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="updateId" name="updateId" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">update_name：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="updateName" name="updateName" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">update_time：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="updateTime" name="updateTime" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">del_flag：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="delFlag" name="delFlag" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">status：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="status" name="status" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div class="ssec-label">remark：</div>
								</td>
								<td>
									<div class="ssec-text normal">
										<input id="remark" name="remark" class="easyui-validatebox textbox"
											data-options="required:true" />
									</div>
								</td>
							</tr>
						</table>
						<div style="padding: 5px; text-align: right;">
							<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
						</div>
					</form>
				</div>
		</body>

		</html>